package org.classdef.analyzer.info.accesstype;

/**
 * 
 * 方法的访问类型
 *
 */
public enum MethodAccessType {
	
	ACC_PUBLIC(0x0001, "ACC_PUBLIC", "public"),
	ACC_PRIVATE(0x0002, "ACC_PRIVATE", "private"),
	ACC_PROTECTED(0x0004, "ACC_PROTECTED", "protected"),
	ACC_STATIC(0x0008, "ACC_STATIC", "static"),
	ACC_FINAL(0x0010, "ACC_FINAL", "final"),
	ACC_SYNCHRONIZED(0x0020, "ACC_SYNCHRONIZED", "synchronized"),
	ACC_BRIDGE(0x0040, "ACC_BRIDGE", "bridge"),
	ACC_VARARGS(0x0080, "ACC_VARARGS", "varargs"),
	ACC_NATIVE(0x0100, "ACC_NATIVE", "native"),
	ACC_ABSTRACT(0x0400, "ACC_ABSTRACT", "abstract"),
	ACC_STRICT(0x0800, "ACC_STRICT", "strictfp"),
	ACC_SYNTHETIC(0x1000, "ACC_SYNTHETIC", "synthetic");
	
	private int type;
	private String name;
	private String shortName;
	
	private MethodAccessType(int type, String name, String shortName){
		this.type = type;
		this.name = name;
		this.shortName = shortName;
	}
	
	public int getType() {
		return type;
	}

	public String getName() {
		return name;
	}

	public String getShortName() {
		return shortName;
	}

	public static String getType(short accessFlags){
		String accessStr = null;
		
		MethodAccessType[] types = values();
		for (int i = 0; i < types.length; i++) {
			int type = types[i].getType();
			if ((accessFlags & type) == type) {
				if(accessStr == null){
					accessStr = types[i].getShortName();
				}else {
					accessStr += " " + types[i].getShortName();
				}
			}
		}
		return accessStr;
	}
}
